package com.yy.chapter5.Utils;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

/**
 * @author yangyao
 * @Description: 文件工具类
 * @date 2018/10/22 10:31
 */
public class FileUtil {

    public static void uploadFile(String uploadDir, MultipartFile files) throws Exception {
        String fileSuffixName = files.getOriginalFilename().substring(files.getOriginalFilename().lastIndexOf("."));
        String fileName = UUID.randomUUID().toString();
        File uploadFileName = new File(uploadDir + File.separator + fileName + fileSuffixName);
        files.transferTo(uploadFileName);
    }
}
